﻿using System;
//using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
//using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
//using System.ServiceModel.Channels;
//using System.ServiceModel;
using System.Threading;
using System.Windows;


namespace WpfApplication1
{
    class Authentication
    {

        private static Random rand = new Random();

        public static String sha256_hash(String salt, String password)
        {
            String value = salt+password+salt;
            String hashedValue = value;
            for (int i = 0; i < 5000; i++)
            {
                StringBuilder Sb = new StringBuilder();

                using (SHA256 hash = SHA256Managed.Create())
                {
                    Encoding enc = Encoding.UTF8;
                    Byte[] result = hash.ComputeHash(enc.GetBytes(hashedValue));

                    foreach (Byte b in result)
                        Sb.Append(b.ToString());
                }
                hashedValue = Sb.ToString();
            }
            return hashedValue;
        }

        public static String getRandomSaltKey()
        {
            int[] saltArr = new int[30];
            string salt = "";
            for (int i = 0; i < saltArr.Length; i++)
            {
                int newChar = rand.Next(62, 126);
                saltArr[i] = newChar != 92 ? newChar : 96;
            }
            foreach (int i in saltArr)
            {
                char temp = (char)i;
                salt += temp.ToString();
            }
            return salt;
        }
    }
}
